package com.adcage.ojudgebackendquestionservice.controller.inner;

import com.adcage.ojudgebackendmodel.entity.Question;
import com.adcage.ojudgebackendmodel.entity.QuestionSubmit;
import com.adcage.ojudgebackendquestionservice.service.QuestionService;
import com.adcage.ojudgebackendquestionservice.service.QuestionSubmitService;
import com.adcage.ojudgebackendserviceclient.service.QuestionFeignClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 该服务仅提供内部调用,不是给前端的服务
 */
@RestController
@RequestMapping("/inner")
public class QuestionInnerController implements QuestionFeignClient {

    @Resource
    private QuestionService questionService;

    @Resource
    private QuestionSubmitService questionSubmitService;


    /**
     * 获取题目
     *
     * @param id
     * @return
     */
    @GetMapping("/get/id")
    @Override
    public Question getById(@RequestParam("id") long id) {
        return questionService.getById(id);
    }

    /**
     * 获取提交
     *
     * @param questionSubmitId
     * @return
     */
    @GetMapping("/question_submit/get/id")
    @Override
    public QuestionSubmit getQuestionSubmitById(@RequestParam("questionSubmitId") long questionSubmitId) {
        return questionSubmitService.getById(questionSubmitId);
    }

    /**
     * 更新提交
     *
     * @param questionSubmit
     * @return
     */
    @PostMapping("/question_submit/update")
    @Override
    public boolean updateQuestionSubmitById(@RequestBody QuestionSubmit questionSubmit) {
        return questionSubmitService.updateById(questionSubmit);
    }

}